﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS.Module
{
    public partial class ucBreadcrumb : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string url = Request.Url.AbsolutePath;
            url = url.Substring(1, url.Length - 1);
            string url1 = url.Replace(".", "/");
            string Module = url1.Substring(0, url1.IndexOf("/"));
            if (Session["lang"].ToString() == "VN")
            {
                lbHome.Text = "Trang chủ ";
                if (Module == "SanPham")
                {
                    if (Request.QueryString["NhanHieu"] != null)
                    {
                        int NhanHieuID = int.Parse(Request.QueryString["NhanHieu"]);
                        string NhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » ";
                        lblTitle.Text += "<a href='/SanPham/NhanHieu/" + NhanHieuID + "/" + FriendlyUrl(NhanHieu) + "'" + ">" + NhanHieu + "</a>";
                    }
                    else if (Request.QueryString["LoaiSP"] != null)
                    {
                        int LoaiSP = int.Parse(Request.QueryString["LoaiSP"]);
                        string title = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSP }).TenLoaiSanPham;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » " + "<a href='/SanPham/LoaiSP/" + LoaiSP + "/" + FriendlyUrl(title) + "'" + ">" + title + "</a>";
                    }
                    else if (Request.QueryString["Filter"] != null)
                    {
                        int LoaiSPID = int.Parse(Session["LoaiSP"].ToString());
                        int NhanHieuID = int.Parse(Request.QueryString["Filter"].ToString());
                        string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).TenLoaiSanPham;
                        string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » " + "<a href='/SanPham/Filter/" + NhanHieuID + "/" + FriendlyUrl(titleNhanHieu) + "'" + ">" + titleLoaiSP + " - " + titleNhanHieu + "</a>";


                    }
                    else if (Request.QueryString["FilterDM"] != null)
                    {
                        int LoaiSPID = int.Parse(Request.QueryString["FilterDM"]);
                        int NhanHieuID = int.Parse(Session["NhanHieu"].ToString());
                        string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).TenLoaiSanPham;
                        string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).TenNhanHieu;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>" + " » " + "<a href='/SanPham/FilterDM/" + LoaiSPID + "/" + FriendlyUrl(titleLoaiSP) + "'" + ">" + titleNhanHieu + " - " + titleLoaiSP + "</a>";


                    }

                    else
                    {
                        lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>";
                    }
                }
                else if (Module == "Search")
                {
                    lblTitle.Text = "<a href='/Search/" + Request.QueryString["ID"].ToString() + "/Tim-Kiem.aspx'> Tìm kiếm \"" + Request.QueryString["ID"].ToString() + "\"</a>";
                }
                else if (Module == "About")
                {
                    if (Request.QueryString["ID"] != null)
                    {
                        int ID = int.Parse(Request.QueryString["ID"]);
                        string title = new cmsCategoryBL().Select(new cmsCategoryDO { CategoryID = ID }).Title;

                        lblTitle.Text = "<a href='/About/" + ID + "/" + FriendlyUrl(title) + "'>" + title + "</a>";
                    }
                }

                else if (Module == "Category")
                {
                    if (Request.QueryString["ID"] != null)
                    {
                        int ID = int.Parse(Request.QueryString["ID"]);
                        if (ID == 7)
                        {
                            lblTitle.Text = "<a href='/Category/7/Tin-Tuc.aspx'>Tin tức</a>";
                        }
                        if (ID != 7)
                        {
                            lblTitle.Text = "<a href='/Category/7/Tin-Tuc.aspx'>Tin tức</a>";
                        }
                    }
                }
                else if (Module == "Article")
                {
                    lblTitle.Text = "<a href='/Category/7/Tin-Tuc.aspx'> Tin tức</a>";
                }
                else if (Module == "Contact")
                    lblTitle.Text = "<a href='/Contact.aspx'> Liên Hệ</a>";
                else if (Module == "ThongTin")
                    lblTitle.Text = "<a href='/ThongTin/" + Session["IDDN"].ToString() + "/Thong-tin-ca-nhan.aspx'> Thông tin cá nhân</a>";
                else if (Module == "DoiMK")
                    lblTitle.Text = "<a href='/DoiMK.aspx'>Đổi mật khẩu</a>";
                else if (Module == "GioHang")
                {
                    lblTitle.Text = "<a href='/GioHang.aspx'> Giỏ hàng </a>";
                }
                else if (Module == "Register")
                {
                    lblTitle.Text = "<a href='/Register.aspx'> Đăng ký thành viên </a>";
                }
                else if (Module == "ThanhToan")
                {
                    lblTitle.Text = "<a href='/ThanhToan.aspx'> Gửi đơn hàng </a>";
                }
                else if (Module == "BaoGia")
                {
                    lblTitle.Text = "<a href='/BaoGia.aspx'> Tải Báo giá </a>";
                }
                else if (Module == "SanPhamChiTiet")
                {
                    cmsSanPhamDO obj = new cmsSanPhamBL().Select(new cmsSanPhamDO { SanPhamID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/SanPham.aspx'> Sản phẩm</a>» <a href='/SanPhamChiTiet/'" + Request.QueryString["ID"].ToString() + "/" + FriendlyUrl(obj.TenSanPham) + "'>" + obj.TenSanPham + "</a>";
                }
                else if (Module == "Album")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>";
                }
                else if (Module == "AlbumCover")
                {
                    try
                    {
                        string url2 = Request.Url.AbsolutePath;
                        cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                        lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>";
                    }
                    catch (Exception t)
                    {
                        lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>";
                    }
                }
                else if (Module == "AlbumImage")
                {
                    string url2 = Request.Url.AbsolutePath;
                    try
                    {
                        cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                        lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Ảnh </a>";
                    }
                    catch (Exception t)
                    {
                        lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Ảnh </a>";
                    }
                }
                else if (Module == "Image")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Ảnh </a>";
                }
                else if (Module == "AlbumDetai")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsImagesDO obj = new cmsImagesBL().Select(new cmsImagesDO { ImageID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>» <a href='/Album/" + obj.AlbumID + "/Album.aspx'>Album - " + new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = obj.AlbumID }).Title + "</a>";
                }
                else
                {
                    lblTitle.Text = "<a href='/" + Module + ".aspx'>" + Module + " </a>";
                }
            }
            else
            {
                lbHome.Text = "Home ";
                if (Module == "SanPham")
                {
                    if (Request.QueryString["NhanHieu"] != null)
                    {
                        int NhanHieuID = int.Parse(Request.QueryString["NhanHieu"]);
                        string NhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).eTenNhanHieu;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Product</a>" + " » ";
                        lblTitle.Text += "<a href='/SanPham/NhanHieu/" + NhanHieuID + "/" + FriendlyUrl(NhanHieu) + "'" + ">" + NhanHieu + "</a>";
                    }
                    else if (Request.QueryString["LoaiSP"] != null)
                    {
                        int LoaiSP = int.Parse(Request.QueryString["LoaiSP"]);
                        string title = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSP }).eTenSanPham;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Product</a>" + " » " + "<a href='/SanPham/LoaiSP/" + LoaiSP + "/" + FriendlyUrl(title) + "'" + ">" + title + "</a>";
                    }
                    else if (Request.QueryString["Filter"] != null)
                    {
                        int LoaiSPID = int.Parse(Session["LoaiSP"].ToString());
                        int NhanHieuID = int.Parse(Request.QueryString["Filter"].ToString());
                        string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).eTenSanPham;
                        string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).eTenNhanHieu;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Product</a>" + " » " + "<a href='/SanPham/Filter/" + NhanHieuID + "/" + FriendlyUrl(titleNhanHieu) + "'" + ">" + titleLoaiSP + " - " + titleNhanHieu + "</a>";


                    }
                    else if (Request.QueryString["FilterDM"] != null)
                    {
                        int LoaiSPID = int.Parse(Request.QueryString["FilterDM"]);
                        int NhanHieuID = int.Parse(Session["NhanHieu"].ToString());
                        string titleLoaiSP = new cmsLoaiSanPhamBL().Select(new cmsLoaiSanPhamDO { LoaiSanPhamID = LoaiSPID }).eTenSanPham;
                        string titleNhanHieu = new cmsNhanHieuBL().Select(new cmsNhanHieuDO { NhanHieuID = NhanHieuID }).eTenNhanHieu;
                        lblTitle.Text = "<a href='/SanPham.aspx'> Product</a>" + " » " + "<a href='/SanPham/FilterDM/" + LoaiSPID + "/" + FriendlyUrl(titleLoaiSP) + "'" + ">" + titleNhanHieu + " - " + titleLoaiSP + "</a>";


                    }

                    else
                    {
                        lblTitle.Text = "<a href='/SanPham.aspx'> Product</a>";
                    }
                }
                else if (Module == "Search")
                {
                    lblTitle.Text = "<a href='/Search/" + Request.QueryString["ID"].ToString() + "/Tim-Kiem.aspx'> Search \"" + Request.QueryString["ID"].ToString() + "\"</a>";
                }
                else if (Module == "About")
                {
                    if (Request.QueryString["ID"] != null)
                    {
                        int ID = int.Parse(Request.QueryString["ID"]);
                        string title = new cmsCategoryBL().Select(new cmsCategoryDO { CategoryID = ID }).eTitle;

                        lblTitle.Text = "<a href='/About/" + ID + "/" + FriendlyUrl(title) + "'>" + title + "</a>";
                    }
                }

                else if (Module == "Category")
                {
                    if (Request.QueryString["ID"] != null)
                    {
                        int ID = int.Parse(Request.QueryString["ID"]);
                        if (ID == 7)
                        {
                            lblTitle.Text = "<a href='/Category/3/Tin-Tuc.aspx'>News</a>";
                        }
                    }
                }
                else if (Module == "Article")
                {
                    lblTitle.Text = "<a href='/Category/3/Tin-Tuc.aspx'> News</a>";
                }
                else if (Module == "Contact")
                    lblTitle.Text = "<a href='/Contact.aspx'> Contact</a>";
                else if (Module == "ThongTin")
                    lblTitle.Text = "<a href='/ThongTin/" + Session["IDDN"].ToString() + "/Thong-tin-ca-nhan.aspx'> Account Info</a>";
                else if (Module == "DoiMK")
                    lblTitle.Text = "<a href='/DoiMK.aspx'>Change Password</a>";
                else if (Module == "GioHang")
                {
                    lblTitle.Text = "<a href='/GioHang.aspx'> Your Cart </a>";
                }
                else if (Module == "Register")
                {
                    lblTitle.Text = "<a href='/Register.aspx'> Register </a>";
                }
                else if (Module == "ThanhToan")
                {
                    lblTitle.Text = "<a href='/ThanhToan.aspx'> Send Orders </a>";
                }
                else if (Module == "BaoGia")
                {
                    lblTitle.Text = "<a href='/BaoGia.aspx'> Download quotation </a>";
                }
                else if (Module == "SanPhamChiTiet")
                {
                    cmsSanPhamDO obj = new cmsSanPhamBL().Select(new cmsSanPhamDO { SanPhamID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/SanPham.aspx'> Product </a>» <a href='/SanPhamChiTiet/'" + Request.QueryString["ID"].ToString() + "/" + FriendlyUrl(obj.TenSanPham) + "'>" + obj.eTenSanPham + "</a>";
                }
                else if (Module == "Album")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>";
                }
                else if (Module == "AlbumImage")
                {
                    try
                    {
                        string url2 = Request.Url.AbsolutePath;
                        cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                        lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Image </a>";
                    }
                    catch (Exception t)
                    {
                        lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Image </a>";
                    }
                }
                else if (Module == "Image")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsAlbumDO obj = new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumImage.aspx'> Album Image </a>» <a href='/" + url + "'> Album - " + obj.eTitle + "</a>";
                }
                else if (Module == "AlbumDetai")
                {
                    string url2 = Request.Url.AbsolutePath;
                    cmsImagesDO obj = new cmsImagesBL().Select(new cmsImagesDO { ImageID = int.Parse(Request.QueryString["ID"].ToString()) });
                    lblTitle.Text = "<a href='/AlbumCover.aspx'> Video </a>» <a href='/Album/" + obj.AlbumID + "/Album.aspx'>Album - " + new cmsAlbumBL().Select(new cmsAlbumDO { AlbumID = obj.AlbumID }).eTitle + "</a>";
                }
                else
                {
                    lblTitle.Text = "<a href='/" + Module + ".aspx'>" + Module + " </a>";
                }
            }
        }

        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
    }
}